package cn.yogehaoren.agile_gateway.config;


import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

/**
 * @author WangNing
 * @since 1.0
 */
@Configuration
public class K8SConfig {

    @Value("${master.url:#{null}}")
    private String masterUrl;

    @Bean
    public KubernetesClient kubernetesClient(){

        if(StringUtils.isEmpty(masterUrl)){
            return new DefaultKubernetesClient();
        }else {
            Config config = new ConfigBuilder().withMasterUrl(masterUrl).build();
            return new DefaultKubernetesClient(config);
        }

    }

}
